#!/usr/bin/env python
import rospy
from trigger_response.srv import event, eventRequest  # 导入服务消息类型


def send_event_request():
    rospy.init_node('event_client', anonymous=True)
    rospy.wait_for_service('eventHandle')  # 等待服务可用

    try:
        client = rospy.ServiceProxy('eventHandle', event)  # 创建服务代理
        req = eventRequest()  # 创建请求
        # req.UavPos = [1, 1, 6]
        # req.UgvPos = [1, 1, 1]
        # req.TargetPos = [1, 4, 1]
        # req.EType = [1, 0, 0, 0]
        # req.eventLocx = [-1, -1, 2, 1]
        # req.eventLocy = [-1, -1, 2, 2]
        # req.eventLocz = [-1, -1, 1, 1]
        req.UavPos = [1, 1, 1]
        req.UgvPos = [1, 1, 1]
        req.TargetPos = [30, 30, 30]
        req.EType = [0, 1, 0, 0]
        req.eventLocx = [-1, 20, -1, -1]
        req.eventLocy = [-1, 20, -1, -1]
        req.eventLocz = [-1, 20, -1, -1]
        print("客户端创建成功")

        resp = client(req)  # 调用服务
        print("Response: %d" % resp.response)
    except rospy.ServiceException as e:
        print("Service call failed: %s" % e)

if __name__ == "__main__":
    send_event_request()